import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.List;

/**
 * Class that handles the events from the main menu screen
 * @author Paula Gonz�lez Mu�oz
 * @author Alex Bruck
 * @author Cem Altel
 */
public class Listener implements CommandListener
{
 	/**
 	 * GUI element which events the Listener is going to handle
 	 */
 	GUI m;
 	
 	/**
 	 * Constructor
 	 * @param m GUI element which events the Listener is going to handle
 	 */
 	public Listener(GUI m)
 	{
 		this.m = m;
 	}
	
 	/** 
 	 * Method that handles the events from the main menu screen
 	 * @param c event to handle
 	 * @param d displayable element to interact with
 	 * @see javax.microedition.lcdui.CommandListener#commandAction(javax.microedition.lcdui.Command, javax.microedition.lcdui.Displayable)
 	 */
 	public void commandAction(Command c, Displayable d)
 	{
 		String label = c.getLabel();
 		
 		if(label.equals("Exit"))
 		{
 			try
 			{
 				m.destroyApp(true);
 			}
 			catch(Exception e)
 			{
 				e.printStackTrace();
 			}
 		}
 		else if (label.equals("Back"))
 		{
 			m.mainMenu();
 		}
 		else
 		{
 			List down = (List)m.display.getCurrent();
 			switch(down.getSelectedIndex())
 			{
 			case 0:
 				m.newTravel();
 				break;
 			}
	 	}	 				
 	}
}